﻿Imports System.Windows.Forms
Imports Logica

Public Class AgregarCuentaContable

    Private Sub AgregarCuentaContable_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblRetroalimentacion.ForeColor = Color.Red
        lblRetroalimentacion.Text = ""
    End Sub
    ''' <summary>
    ''' Accion de link de ayuda.
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 22/06/2010</remarks>
    Private Sub lnkAyuda_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
        Dim ayuda As New MostrarAyuda
        Dim ubicacion As New Point(250, 100)

        ayuda.Visible = True
        ayuda.Location = ubicacion
    End Sub

    ''' <summary>
    ''' Accion del boton de Ok. Este Valida los campos a registrar y agegar la cuenta contable.
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 21/06/2010</remarks>
    Private Sub OK_Button_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Try
            For Each c As Control In Me.Controls
                If TypeOf c Is TextBox Then
                    If c.Text = "" Or c.Text.Trim = "" Then
                        c.Focus()
                        lblRetroalimentacion.ForeColor = Color.Red
                        lblRetroalimentacion.Text = "El campo '" & c.Tag & "' está vacío."
                        Exit Sub
                    End If
                End If
            Next
            Gestor.registrarCuenta(txtCodigo.Text, txtDescripcion.Text)
            txtCodigo.Text = ""
            txtDescripcion.Text = ""
        Catch sqlEx As SqlClient.SqlException When sqlEx.Number = 2627
            lblRetroalimentacion.ForeColor = Color.Red
            lblRetroalimentacion.Text = "Ya existe una cuenta contable con ese código."
            Exit Sub
        Catch sqlEx As SqlClient.SqlException
            lblRetroalimentacion.ForeColor = Color.Red
            lblRetroalimentacion.Text = "Error de Conexión."
            Exit Sub
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub
    ''' <summary>
    ''' Controla el cambio en el campo de Código
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 28/06/2010 Modificado: 28/06/2010</remarks>
    Private Sub txtCodigo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCodigo.KeyPress
        If Char.IsLetterOrDigit(e.KeyChar) Then
            e.Handled = False
        ElseIf Char.IsControl(e.KeyChar) Then
            e.Handled = False
        Else
            lblRetroalimentacion.ForeColor = Color.Red
            lblRetroalimentacion.Text = "No se pueden ingresar simbolos en el" + vbCrLf + " campo de '" & txtCodigo.Tag & "'."
            e.Handled = True
        End If
    End Sub
    ''' <summary>
    ''' Limpia los campos modificables
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 28/06/2010 Modificado: 28/06/2010</remarks>
    Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        txtCodigo.Text = ""
        txtDescripcion.Text = ""
        lblRetroalimentacion.Text = ""
    End Sub

    ''' <summary>
    ''' Accion del boton de cancelar.
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 28/06/2010 Modificado: 28/06/2010</remarks>
    Private Sub Cancel_Button_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
End Class
